<template>
  <el-row>
    <el-col :span="12">
      <div class="form-main" ref="formBox">
        <el-card>
          <div slot="header" class="text-primary">
            <span class="title"> 个人资料 </span>
          </div>
          <el-form ref="form" :model="form" status-icon label-width="80px">
            <el-form-item label="用户名" prop="username">
              <el-input disabled v-model="form.username"></el-input>
            </el-form-item>

            <el-form-item label="姓名" prop="realname">
              <el-input v-model="form.realname"></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="gender">
              <el-radio-group v-model="form.gender">
                <el-radio label="男"></el-radio>
                <el-radio label="女"></el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="出生日期" prop="birthday">
              <el-date-picker
                v-model="form.birthday"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item label="电话" prop="tel">
              <el-input v-model="form.tel"></el-input>
            </el-form-item>

            <el-form-item label="地址" prop="address">
              <el-input v-model="form.address"></el-input>
            </el-form-item>

            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email"></el-input>
            </el-form-item>
            <div>
              <el-button
                style="margin-left: 80px"
                @click="submitForm('form')"
                type="primary"
                >提交</el-button
              >
            </div>
          </el-form></el-card
        >
      </div>
    </el-col>
  </el-row>
</template>
<script>
import { getInfo, updateInfo } from '@/api/accountApi'
export default {
  data() {
    return {
      windowHeight: 0,

      layHeight: '600px',
      form: {
        username: '',
        password: '',
        pwdConfirm: '',
        realname: '',
        gender: '男',
        tel: '',
        email: '',
        address: '',
        birthday: '1999-09-09',
        avatar: '',
      },
    }
  },
  created() {
    this.$nextTick(() => {
      this.getInfo()
    })
  },
  methods: {
    submitForm(formName) {
      console.log(this.form);
      updateInfo(this.form).then((resp) => {
        let response = resp.data

        if (response.code == 1) {
          this.$message({
            message:response.message,
            type:'success'
          })
           this.getInfo()
        } else {
        this.$message({
            message:response.message,
            type:'error'
          })
        }
      })
    },
    getInfo() {
      let account = JSON.parse(localStorage.getItem('account'))
      let account_id = account.id
     // console.log(this.$route.params)
      if (this.$route.query.id) account_id = this.$route.query.id
      getInfo({ id: account_id }).then((resp) => {
        let response = resp.data
        
        if (response.code == 1) {
          this.form = response.data
        } else {
          this.$message('获取信息失败')
        }
        console.log(resp)
      })

      console.log('account_id:' + account_id)
    },
  },
}
import '@/assets/css/variables.css'
</script>
<style scoped>
.el-card {
  background: var(--bg-color);
  color: var(--text-color);
  border-color: var(--border-color);
}
::v-deep .el-card__header {
  border-bottom: 1px solid var(--border-color);
}
::v-deep .el-input__inner {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}
::v-deep .el-input.is-disabled .el-input__inner {
  background-color: var(--bg-color); border: 1px solid var(--border-color);
}
</style>
